package com.lastcrdg.textcustomview.CustomView;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * author：liluo
 * e-mail：lastcrazysun@163.com
 * company：cusc
 * date：2017/9/30 10:34
 * description：
 */

public class TextPath extends View {
    private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private int width;
    private int height;

    public TextPath(Context context) {
        super(context);
    }

    public TextPath(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    public TextPath(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        width = MeasureSpec.getSize(widthMeasureSpec);
        height = MeasureSpec.getSize(heightMeasureSpec);
    }

    private void initPaint() {
        mPaint.setColor(Color.BLUE);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(10);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.translate(width / 2, height / 2);
        Paint colorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        colorPaint.setColor(Color.RED);
        canvas.drawLine(-width/2, 0, width/2, 0, colorPaint);
        canvas.drawLine(0, -height/2, 0, height/2, colorPaint);
        Path path = new Path();
        path.lineTo(200,200);
//        path.lineTo(500, 500);
//        path.setLastPoint(200, 600);
//        path.moveTo(300,600);
//        path.lineTo(200, 800);
//        path.close();
//        path.addRect(500,0,0,500, Path.Direction.CCW);
//        path.setLastPoint(300,400);
//        Path src = new Path();
//        path.addRect(-200, -200, 200, 200, Path.Direction.CW);
//        src.addCircle(0, 0, 200, Path.Direction.CW);
//        path.addPath(src, 400, 0);
//        RectF rect = new RectF(-300,-300,300,300);
//        path.addArc(rect, 0 , 180);
//        path.arcTo(rect,0,180);
        path.addCircle(0, 0, 200, Path.Direction.CW);
        Path dst = new Path();
        path.offset(0, 300, dst);
        canvas.drawPath(path, mPaint);
        canvas.drawPath(dst, mPaint);
    }
}
